﻿using LumiSoft.Net.Log;
using RPAVIEW.util;
using RPAVIEW.views.controlLibrary;
using RPAVIEW.views.OtherPages;
using SUNRPA.CONTROLS.IMPL.domain.flowItemParam;
using SUNRPA.CONTROLS.IMPL.util;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Text;
using System.Threading;
using System.Windows.Automation;
using System.Windows.Controls;
namespace RPAVIEW.views.EditPage.flows.GetWinWindowObjN {
    /// <summary>
    /// Input.xaml 的交互逻辑
    /// </summary>
    public partial class Input:BaseParamViewAction{
        public static LogUtil logger = new LogUtil(typeof(Input));
        List<string> classNames = new List<string>();
        List<string> titles = new List<string>();
        public Input() {
            InitializeComponent();
            List<IntPtr> windowHnds = WindowUtil.GetProcessWindows();
            foreach(IntPtr ptr in windowHnds) { 
                AutomationElement ae = AutomationElement.FromHandle(ptr);
                if(!string.IsNullOrEmpty(ae.Current.ClassName)) { 
                    classNames.Add(ae.Current.ClassName);
                }
                if(!string.IsNullOrEmpty(ae.Current.Name)) { 
                    titles.Add(ae.Current.Name);
                }
            }
            this.title.ItemsSource = titles;
            this.className.ItemsSource = classNames;
        }

        public override void UpdateSource() {
            this.getWindowMethod.GetBindingExpression(ComboBox.SelectedIndexProperty).UpdateSource();
            this.title.GetBindingExpression(ComboBox.SelectedItemProperty).UpdateSource();
            this.className.GetBindingExpression(ComboBox.SelectedItemProperty).UpdateSource();
            this.isPattern.GetBindingExpression(CheckBox.IsCheckedProperty).UpdateSource();
        }

        private void GetElement(object sender, System.Windows.RoutedEventArgs e) {
            MainWindow main = WindowUtil.GetWindow<MainWindow>();
            WindowUtil.MinSizeWindow(main);
            GetEleWindow eleWindow = new GetEleWindow((ele)=>{

            });
            eleWindow.Show();
            eleWindow.RegistHotKey();
        }

        private void GetMethodChanged(object sender, SelectionChangedEventArgs e) {
            int getMethod = this.getWindowMethod.SelectedIndex;
            switch(getMethod) {
                case 0:
                    //标题或者类名
                    ElementUtil.HideRow(this.catchRow);
                    ElementUtil.ShowRow(this.titileRow);
                    ElementUtil.ShowRow(this.classRow);
                    ElementUtil.ShowRow(this.patternRow);
                    break;
                case 1:
                    //捕捉
                    ElementUtil.ShowRow(this.catchRow);
                    ElementUtil.HideRow(this.titileRow);
                    ElementUtil.HideRow(this.classRow);
                    ElementUtil.HideRow(this.patternRow);
                    break;
                case 2:
                    //当前窗口
                    ElementUtil.HideRow(this.catchRow);
                    ElementUtil.HideRow(this.titileRow);
                    ElementUtil.HideRow(this.classRow);
                    ElementUtil.HideRow(this.patternRow);
                    break;
                case 3:
                    //桌面
                    ElementUtil.HideRow(this.catchRow);
                    ElementUtil.HideRow(this.titileRow);
                    ElementUtil.HideRow(this.classRow);
                    ElementUtil.HideRow(this.patternRow);
                    break;
                default:
                    break;
            }
        }
    }
}
